xl: track child processes for the benefit of libxl
authorIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 29 May 2012 09:31:37 +0000 (10:31 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 29 May 2012 09:31:37 +0000 (10:31 +0100)
commit8d7aec41547d798761dcb308387f276667f9989a
tree34f19025dcc497e0d0fc6786edca8b6d78093f80
parent017c08fa0da81e62c85ef5a018af2fe665acbbaf
xl: track child processes for the benefit of libxl

Each time xl forks, it needs to record the pid, so that its exit
status can be preserved if it happens that libxl's event loop reaped
it.  Consequently we also have a new wrapper for waitpid, which in
that case returns the previously-reaped status.

When we get a console ready callback from libxl, check to see if we
have spawned but not reaped a previous console client, and if so reap
it now.  (This is necessary to prevent improper use of the xlchild
struct, but has the happy consequence of checking the exit status of
the first console client in the pygrub case.)

Refactor the two calls to libxl_ctx_alloc into a new function
xl_ctx_alloc which also sets the child reaped handler callback.

All of this has the effect of suppressing a message
   unknown child [nnnn] unexpected exited status zero
which would sometimes (depending on a race) appear with `xl create -c'
and pygrub.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Reported-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Cc: Roger Pau Monne <roger.pau@citrix.com>
[ ijc -- corrected return codes in xl_reaped_callback to match documented
         convention. ]
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/xl.c
tools/libxl/xl.h
tools/libxl/xl_cmdimpl.c